package net.pragyah.scalby.inference.approximate

import junit.framework.TestCase
import junit.framework.Assert._
 
import net.pragyah.scalby._

import net.pragyah.scalgorithms.graphs._

class TestLogicSampling extends TestCase{
  
  	val x1 = new Variable[int]("X1",Set[int]()+1+2,None) 
  	val x2 = new Variable[int]("X2",Set[int]()+1+2,None) 
  	val x3 = new Variable[int]("X3",Set[int]()+1+2,None) 
  	val x4 = new Variable[int]("X4",Set[int]()+1+2,None) 
  	val x5 = new Variable[int]("X5",Set[int]()+1+2,None) 

	
	val X1 = Vertex[Variable[int]](x1);
	val X2 = Vertex[Variable[int]](x2);
	val X3 = Vertex[Variable[int]](x3);
	val X4 = Vertex[Variable[int]](x4);
	val X5 = Vertex[Variable[int]](x5);

	
	val P = ProbabilityDistribution[int]()
	
	val graph:Graph[Variable[int]] = Graph[Variable[int]](Nil,true)

    def testLogicSampling(){
      val samplingAlgo = new LogicSampling[int](graph,P,Set())
      
      val estimate = samplingAlgo.estimate(100);
      println(estimate)
      null
    }
 
     /// SETUP 
    
	    val all = X1::X2::X3::X4::X5::Nil 
	    graph ++  all//adding all the vertices
     
     
        graph.addEdge(X1,X2)
        graph.addEdge(X1,X3)
        graph.addEdge(X2,X4)
        graph.addEdge(X2,X5)
        graph.addEdge(X3,X5)
        
        P(x1,1,Map[Variable[int],int](),0.5f);
        P(x1,2,Map[Variable[int],int](),0.5f);

        P(x2,1,Map[Variable[int],int]((x1,1)),0.8f);
        P(x2,2,Map[Variable[int],int]((x1,1)),0.2f);
        P(x2,1,Map[Variable[int],int]((x1,2)),0.1f);
        P(x2,2,Map[Variable[int],int]((x1,2)),0.9f);

        P(x3,1,Map[Variable[int],int]((x1,1)),0.7f);
        P(x3,2,Map[Variable[int],int]((x1,1)),0.3f);
        P(x3,1,Map[Variable[int],int]((x1,2)),0.4f);
        P(x3,2,Map[Variable[int],int]((x1,2)),0.6f);


        P(x4,1,Map[Variable[int],int]((x2,1)),0.6f);
        P(x4,2,Map[Variable[int],int]((x2,1)),0.4f);
        P(x4,1,Map[Variable[int],int]((x2,2)),0.1f);
        P(x4,2,Map[Variable[int],int]((x2,2)),0.9f);

      
        P(x4,1,Map[Variable[int],int]()+((x2,1))+((x3,1)),0.1f);
        P(x4,2,Map[Variable[int],int]()+((x2,1))+((x3,1)),0.9f);
        P(x4,1,Map[Variable[int],int]()+((x2,1))+((x3,2)),0.2f);
        P(x4,2,Map[Variable[int],int]()+((x2,1))+((x3,2)),0.8f);
        P(x4,1,Map[Variable[int],int]()+((x2,2))+((x3,1)),0.3f);
        P(x4,2,Map[Variable[int],int]()+((x2,2))+((x3,1)),0.7f);
        P(x4,1,Map[Variable[int],int]()+((x2,2))+((x3,2)),0.4f);
        P(x4,2,Map[Variable[int],int]()+((x2,2))+((x3,2)),0.6f);




}
